﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Plat.DataRepository;

namespace Plat.WfProcess.Business
{
    /// <summary>
    /// 流程定义管理类
    /// </summary>
    public class ProcessManager
    {
        #region 属性、构造函数
        private ProcessRepository _processRepository;
        private ProcessRepository processRepository
        {
            get
            {
                if (_processRepository == null)
                {
                    _processRepository = new ProcessRepository();
                }
                return _processRepository;
            }
        }

        public ProcessManager()
        {
        }
        #endregion

        #region 获取流程数据
        public ProcessEntity Select(string processGUID)
        {
            return processRepository.SelectById(processGUID);
        }

        public ProcessEntity SelectByName(string processName)
        {
            string where = "ProcessName == @0";
            return processRepository.Select(where, processName).FirstOrDefault();
        }

        public IList<ProcessEntity> SelectAll()
        {
            return processRepository.SelectAll();
        }

        public IList<ProcessEntity> Select(int pageIndex,
            int pageSize,
            out long allRowsCount,
            string orderBy,
            string where,
            params object[] values)
        {
            return processRepository.Select(pageIndex, pageSize, out allRowsCount, orderBy, false, where, values);
        }

        #endregion

        #region 新增、更新和删除流程数据
        public string Insert(ProcessEntity entity)
        {
            return processRepository.Insert(entity).ProcessGUID.ToString();
        }

        public void Update(ProcessEntity entity)
        {
            processRepository.Update(entity);
        }

        public void Delete(string processGUID)
        {
            processRepository.Delete(processGUID);
        }
        #endregion 
    }
}
